package com.hnkywl.sts.action.zjgl;

/**
 * Created by lw on 2015/11/9.
 */

import com.hnkywl.sts.entity.zjgl.Zr;
import com.hnkywl.sts.service.zjgl.YypfService;
import com.hnkywl.sts.service.zjgl.ZrService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 说明：
 * 包:        com.hnkywl.sts.action.zjgl
 * 类描述:    异议赔付Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/zjgl/zr")
public class ZrAction extends SimpleActionSupport {
    private ZrService zrService;
    private YypfService yypfService;
    //合同编号
    private String htbm;
    //id
    private Long zrId;
    //实体类实例化
    private Zr zr;
    private int page;
    //分页组件 页面大小
    private int rows = 10;

    @Action("zrList")
    public void zrList() {
        this.renderJson(this.zrService.findAllZr(htbm, page, rows));
    }

    @Action("zr_content")
    public String zr_content() {
        //进入update页面
        if (zrId != null) {
            zr = zrService.findZrDetail(zrId);
        } else {
            zr = new Zr();
        }
        return SUCCESS;
    }

    /**
     * 增加
     */
    @Action("add_zr")
    public void addZr() {
        try {
            this.zrService.addZr(zr);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 修改
     */
    @Action("update_zr")
    public void updateZr() {
        try {
            this.zrService.updateZr(zr, zrId);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 删除
     */
    @Action("del_zr")
    public void del_zr() {
        try {
            this.zrService.delZr(zrId);
            renderText("{\"statusCode\":\"200\",\"message\":\"删除成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 下拉合同的查询分页
     */
    @Action("xlhtList")
    public void xlhtList() {
        renderJson(this.yypfService.findXlht(page, rows));
    }

    @Autowired
    public void setZrService(ZrService zrService) {
        this.zrService = zrService;
    }

    @Autowired
    public void setYypfService(YypfService yypfService) {
        this.yypfService = yypfService;
    }

    public String getHtbm() {
        return htbm;
    }

    public void setHtbm(String htbm) {
        this.htbm = htbm;
    }

    public Long getZrId() {
        return zrId;
    }

    public void setZrId(Long zrId) {
        this.zrId = zrId;
    }

    public Zr getZr() {
        return zr;
    }

    public void setZr(Zr zr) {
        this.zr = zr;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }
}
